//
//  Stats_ClientOptions.cpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2013-2014 Razvan Coca (razvan dot coca at  gmail dot com)
// This is mostly generated code. Generator is distributed under GPL. Edit it to suit your needs.
// 



#include "Stats_ClientOptions.hpp"

bool Stats_ClientOptions::Parse(std::string const& ConfigName,int argc,char *argv[],boost::shared_ptr<ValueTypeMap> pVM)
{

        boost::program_options::options_description description("Stats_Client options");
        endpoint  net_mgroup;
        endpoint  net_local_if;
        int  net_ttl;
        int  net_flight_base;
        int  net_flight_incr;
        int  net_nitems;
        std::string  net_cluster;
        std::string  net_node;
        std::string  encrypt_iv;
        std::string  encrypt_key;
        std::string  get_key;
        double  get_value;
        std::string  set_key;
        double  set_value;
        std::string  log_path;
        ;
        description.add_options()
        ("help", "help message")
        ("debug","debug run")
        ("net.mgroup",boost::program_options::value< endpoint >(&net_mgroup) ->required(),"net mgroup: ip_port (ex:239.44.12.23:2447)")
        ("net.local_if",boost::program_options::value< endpoint >(&net_local_if) ,"net local_if: ip_port (ex:0.0.0.0:0 )")
        ("net.ttl",boost::program_options::value< int >(&net_ttl) ->default_value(1),"net ttl: int (ex:1 )")
        ("net.flight_base",boost::program_options::value< int >(&net_flight_base) ->default_value(300),"net flight_base: int (ex:1000 )")
        ("net.flight_incr",boost::program_options::value< int >(&net_flight_incr) ->default_value(20),"net flight_incr: int (ex:10   )")
        ("net.nitems",boost::program_options::value< int >(&net_nitems) ->default_value(3),"net nitems: int (ex:3    )")
        ("net.cluster",boost::program_options::value< std::string >(&net_cluster) ->required(),"net cluster: string (ex:cluster1)")
        ("net.node",boost::program_options::value< std::string >(&net_node) ->required(),"net node: string (ex:node2)")
        ("encrypt.iv",boost::program_options::value< std::string >(&encrypt_iv) ->required(),"encrypt iv: string (ex:52CBAB9E3004BF42642C8AC0871B4DF9)")
        ("encrypt.key",boost::program_options::value< std::string >(&encrypt_key) ->required(),"encrypt key: string (ex:D9007ED97246FCC5AC65F7D2FFEE22B9)")
        ("get.key",boost::program_options::value< std::string >(&get_key) ,"get key: string (ex:load )")
        ("get.value",boost::program_options::value< double >(&get_value) ,"get value: float (ex:22.3 )")
        ("set.key",boost::program_options::value< std::string >(&set_key) ,"set key: string (ex:load )")
        ("set.value",boost::program_options::value< double >(&set_value) ,"set value: float (ex:22.3 )")
        ("log.path",boost::program_options::value< std::string >(&log_path) ->default_value("/tmp/logs"),"log path: string (ex:logs )")
        ;
        boost::program_options::variables_map vars_map;
        boost::program_options::store(boost::program_options::parse_command_line(argc,argv,description),vars_map);
        if(vars_map.count("help"))std::cout<<description<<std::endl;
        if(vars_map.count("debug"))std::cout<<"debug mode"<<std::endl;
        //if config is a usefull parameter in ctor, then use it, else ignore it
        if(ConfigName.size())
        {
            std::ifstream conf(ConfigName.c_str());
            if(conf.is_open())
                boost::program_options::store(boost::program_options::parse_config_file(conf,description),vars_map);
            else
                throw std::runtime_error(ConfigName+":"+std::strerror( errno ));
            //override config with command line
            boost::program_options::store(boost::program_options::parse_command_line(argc,argv,description),vars_map);
        }
        boost::program_options::notify(vars_map);
        if(vars_map["net.mgroup"].defaulted()||vars_map.count("net.mgroup"))pVM->insert(std::make_pair("net.mgroup", ValueType(net_mgroup)));
        if(vars_map["net.local_if"].defaulted()||vars_map.count("net.local_if"))pVM->insert(std::make_pair("net.local_if", ValueType(net_local_if)));
        if(vars_map["net.ttl"].defaulted()||vars_map.count("net.ttl"))pVM->insert(std::make_pair("net.ttl", ValueType(net_ttl)));
        if(vars_map["net.flight_base"].defaulted()||vars_map.count("net.flight_base"))pVM->insert(std::make_pair("net.flight_base", ValueType(net_flight_base)));
        if(vars_map["net.flight_incr"].defaulted()||vars_map.count("net.flight_incr"))pVM->insert(std::make_pair("net.flight_incr", ValueType(net_flight_incr)));
        if(vars_map["net.nitems"].defaulted()||vars_map.count("net.nitems"))pVM->insert(std::make_pair("net.nitems", ValueType(net_nitems)));
        if(vars_map["net.cluster"].defaulted()||vars_map.count("net.cluster"))pVM->insert(std::make_pair("net.cluster", ValueType(net_cluster)));
        if(vars_map["net.node"].defaulted()||vars_map.count("net.node"))pVM->insert(std::make_pair("net.node", ValueType(net_node)));
        if(vars_map["encrypt.iv"].defaulted()||vars_map.count("encrypt.iv"))pVM->insert(std::make_pair("encrypt.iv", ValueType(encrypt_iv)));
        if(vars_map["encrypt.key"].defaulted()||vars_map.count("encrypt.key"))pVM->insert(std::make_pair("encrypt.key", ValueType(encrypt_key)));
        if(vars_map["get.key"].defaulted()||vars_map.count("get.key"))pVM->insert(std::make_pair("get.key", ValueType(get_key)));
        if(vars_map["get.value"].defaulted()||vars_map.count("get.value"))pVM->insert(std::make_pair("get.value", ValueType(get_value)));
        if(vars_map["set.key"].defaulted()||vars_map.count("set.key"))pVM->insert(std::make_pair("set.key", ValueType(set_key)));
        if(vars_map["set.value"].defaulted()||vars_map.count("set.value"))pVM->insert(std::make_pair("set.value", ValueType(set_value)));
        if(vars_map["log.path"].defaulted()||vars_map.count("log.path"))pVM->insert(std::make_pair("log.path", ValueType(log_path)));
        if(vars_map.count("debug"))pVM->insert(std::make_pair("debug",ValueType(1)));
        else pVM->insert(std::make_pair("debug",ValueType(0)));
        if(vars_map.count("help"))pVM->insert(std::make_pair("help",ValueType(1)));
        else pVM->insert(std::make_pair("help",ValueType(0)));
        return true;
}
